package bairui.international.weixin.portal.miniapp.controller.barter.score;

import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.querydsl.QSort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;

import bairui.international.model.domain.jpa.TB_UserGradeRecord;
import bairui.international.model.status.State_ProductOrder;
import bairui.international.model.type.Type_UserGrade;
import bairui.international.service.Service_UserGradeRecord;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 *
 * 列表
 *
 * @generated
 * 
 * @see STest_C_Barter_Score_Page_Get 测试
 *
 */
@Controller
public class C_Barter_Score_Page_Get
 extends SC_Barter_Score_Page_Get 
{
	
	@Autowired private Service_UserGradeRecord service_UserGradeRecord;
	
	/**
	 * Get请求
	 */
	@Action(Get.class)
	@GetMapping(Get.RequestMappingValue)
	public @FomatOutput @ResponseBody Object get(
		ModelMap map, HttpServletRequest request,
		@RequestParam Integer startPage,
		@RequestParam String skey
	) throws Exception {
		Page<TB_UserGradeRecord> page = service_UserGradeRecord.page(
				it->it.user.skey.eq(skey),
				PageRequest.of(startPage, 5),
				it->new QSort(it.createTime.desc())
			);
		return page.map(it->new Output(
				it.getId(), 
				new SimpleDateFormat("yyyy年MM月dd日 h点m分").format(it.getCreateTime()),
				it.getScore(),
				it.getCurrentScore(),
				it.getType(),
				it.getType().getComment(),
				it.getState()
			));
	}
	
	@AllArgsConstructor
	public static class Output {
		@Getter private long id;
		@Getter private String createTime;
		@Getter private Double score;
		@Getter private Double currentScore;
		@Getter private Type_UserGrade type;
		@Getter private String typeComment;
		@Getter private State_ProductOrder state;
	}
	

}
